package cn.xinfei.xdecision.common.utils.enums.enginex;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 组件版本状态枚举
 * Created by maying on 2023/03/02.
 **/
@Getter
@AllArgsConstructor
public enum ComponentVersionStatusEnum {
	NEW(0,"新建"),
	ENABLE(1, "锁定");

	private final Integer status;

	private final String name;

	private static final Map<Integer, ComponentVersionStatusEnum> idIndex = new HashMap<>(ComponentVersionStatusEnum.values().length);

	static {
		for (ComponentVersionStatusEnum idEnum : ComponentVersionStatusEnum.values()) {
			idIndex.put(idEnum.getStatus(), idEnum);
		}
	}

	public static ComponentVersionStatusEnum get(Integer code) {
		if (Objects.isNull(code)) {
			return null;
		}
		return idIndex.get(code);
	}

	public static String getNameByStatus(Integer code){
		if (Objects.isNull(code)) {
			return "";
		}
		ComponentVersionStatusEnum statusEnum = idIndex.get(code);
		return statusEnum == null ? "" : statusEnum.getName();
	}
}
